home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
UPC12BS1.ZIP
/
MAIL
/
ADDRESS.C
next >
Wrap
C/C++ Source or Header
|
1993-06-21
|
28KB
|
694 lines
/*--------------------------------------------------------------------*/
/* a d d r e s s . c */
/* */
/* Address parsing routines for UUPC/extended */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* Changes Copyright (c) 1990-1993 by Kendra Electronic */
/* Wonderworks. */
/* */
/* All rights reserved except those explicitly granted by the */
/* UUPC/extended license agreement. */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* RCS Information */
/*--------------------------------------------------------------------*/
/*
* $Id: address.c 1.7 1993/06/22 00:55:45 ahd Exp $
*
* Revision history:
* $Log: address.c $
* Revision 1.7 1993/06/22 00:55:45 ahd
* Trap routing entries when aliasing systems
*
* Revision 1.6 1993/06/21 04:04:04 ahd
* Don't fail routing loops from aliased systems with no route
*
* Revision 1.5 1993/06/21 02:17:31 ahd
* Correct errors in mail routing via HOSTPATH
*
*/
/*--------------------------------------------------------------------*/
/* System include files */
/*--------------------------------------------------------------------*/
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
/*--------------------------------------------------------------------*/
/* UUPC/extended include files */
/*--------------------------------------------------------------------*/
#include "lib.h"
#include "hlib.h"
#include "address.h"
#include "hostable.h"
#include "security.h"
/*--------------------------------------------------------------------*/
/* Global variables */
/*--------------------------------------------------------------------*/
currentfile();
/*--------------------------------------------------------------------*/
/* Local function prototypes */
/*--------------------------------------------------------------------*/
static char *rfc_route( char *tptr, char **nptr, char **pptr );
/*--------------------------------------------------------------------*/
/* u s e r _ a t _ n o d e */
/* */
/* break a UUCP path or RFC-822 address into the basic user and */
/* node components */
/* */
/* Note: This routine assume an address of the form */
/* path!node1!user@node2 is for a user@node1 routed via */
/* node2 and then path. */
/*--------------------------------------------------------------------*/
void user_at_node(const char *raddress,
char *hispath,
char *hisnode,
char *hisuser)
{
static char *saveaddr = NULL;
static char *savepath;
static char *savenode;
static char *saveuser;
char *uptr; /* Pointer to his user id */
char *nptr; /* Pointer to his node id */
char *pptr; /* Pointer to next node in path to him */
char *tptr; /* Temporary token pointer */
char *wptr; /* Work pointer (not used between
steps */
char *address;
struct HostTable *Hptr = NULL; /* Pointer to host name table */
if ( strlen( raddress ) >= MAXADDR )
{
printmsg(0,"Unable to process %d length address: %s",
strlen(raddress) , raddress );
panic();
}
/*--------------------------------------------------------------------*/
/* Determine if local address */
/*--------------------------------------------------------------------*/
if (!strpbrk(raddress,"%!@")) /* Any host delimiters? */
{ /* No --> report local data */
strcpy(hisuser,raddress);
strcpy(hisnode,E_nodename);
strcpy(hispath,E_nodename);
strcpy(hisuser,raddress);
printmsg(5,"user_at_node: Address '%s' is local",raddress);
return;
}
/*--------------------------------------------------------------------*/
/* If the current address is the same as the last processed remote */
/* address, then return the same information as what we determined */
/* last time. */
/*--------------------------------------------------------------------*/
if ((saveaddr != NULL) && equal(raddress,saveaddr))
{
strcpy(hispath,savepath);
strcpy(hisnode,savenode);
strcpy(hisuser,saveuser);
return;
}
/*--------------------------------------------------------------------*/
/* The address is different; save the new address and then proceed */
/* to parse it. */
/*--------------------------------------------------------------------*/
address = strdup(raddress); /* Copy address for parsing */
checkref(address); /* Verify allocation worked */
if (saveaddr != NULL) /* Was the data previously allocated? */
{ /* Yes --> Free it */
free(saveaddr);
}
saveaddr = strdup(address); /* Remember address for next pass */
/*--------------------------------------------------------------------*/
/* If the address has no at sign (@), but does have a percent */
/* sign (%), replace the last percent sign with an at sign. */
/*--------------------------------------------------------------------*/
if ( strchr(address,'@') == NULL ) // Any at signs?
{ // No --> Look further for %
wptr = strrchr(address,'%'); // Locate any percent signs
if ( wptr != NULL ) // Got one?
*wptr = '@'; // Yup --> Make it an at sign at
}
/*--------------------------------------------------------------------*/
/* Initialize routing information */
/*--------------------------------------------------------------------*/
nptr = nil(char); /* No known node for user */
pptr = E_mailserv; /* Default routing via mail server */
tptr = address; /* Remember start of address */
/*--------------------------------------------------------------------*/
/* The address may be RFC-822 syntax; attempt to parse that format */
/*--------------------------------------------------------------------*/
uptr = tptr = rfc_route( tptr, &nptr, &pptr );
/*--------------------------------------------------------------------*/
/* If the user had an RFC-822 path, then the pointer to the path is */
/* now initialized, and the remainder of the path has been dropped */
/* from *tptr; otherwise, the entire address is found via *tptr */
/*--------------------------------------------------------------------*/
wptr = strrchr(tptr,'@'); /* Get last at sign, since it's right
to left scan (more or